/*
 *  $Id: NumberEndingPhrasePart.cs 1184 2010-11-10 17:05:55Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using System;

namespace Ragima.Languages.PhraseParts {
    /// <summary>
    /// Часть фразы: окончание, зависящее от числа, на русском языке.
    /// </summary>
    public class RussianNumberEndingPhrasePart : NumberEndingPhrasePart {
        public RussianNumberEndingPhrasePart(int argNum, string[] variants) : base(argNum, variants) {
        }

        public override int GetNumberIndex(int arg) {
            int n = Math.Abs(arg) % 100;
            if (n >= 11 && n <= 19)
                return 2;
            n %= 10;
            if (n == 1)
                return 0;
            else if (n >= 2 && n <= 4)
                return 1;
            else
                return 2;
        }

        public sealed class RussianNumberEndingParser : NumberEndingParser {
            protected override PhrasePart Create(int argNum, string[] variants) {
                return new RussianNumberEndingPhrasePart(argNum, variants);
            }
        }
    }
}
